package diStringMatch;

public class Solution {
    public int[] diStringMatch(String s) {
        // 贪心 s[i] == 'I' s[i] = min
        //     s[i] == 'D' s[i] = max
        int max = s.length();
        int min = 0;
        int[] prem = new int[s.length()+1];
        for (int i = 0; i < s.length(); i++) {
            prem[i] = s.charAt(i) == 'I'?min++:max--;
        }
        prem[s.length()] = min;
        return prem;
    }
}
